package noticedao

import (
	"fmt"
	"github.com/gogf/gf/v2/frame/g"
	"time"
	"xr-game-server/core/constants/common"
	"xr-game-server/core/constants/db"
	"xr-game-server/dto/noticedto"
	"xr-game-server/entity"
)

func GetAllStatus() []*entity.Notice {
	ret := make([]*entity.Notice, common.Zero)
	g.Model(string(entity.TbNotice)).Unscoped().Where(fmt.Sprintf("%s > ?", entity.NoticeEndTime), time.Now()).Scan(&ret)
	return ret
}

func Page(req *noticedto.GetNoticeReq) (total int, ret []*entity.Notice) {
	ret = make([]*entity.Notice, common.Zero)
	g.Model(string(entity.TbNotice)).Unscoped().Limit(req.PageIndex*req.PageSize, req.PageSize).OrderDesc(string(db.CreatedAtName)).ScanAndCount(&ret, &total, false)
	return
}

func Delete([]uint64) {
	g.Model(string(entity.TbNotice)).WhereIn(string(db.IdName), []uint64{}).Delete()
}

func Save(notice *entity.Notice) {
	g.Model(string(entity.TbNotice)).Save(notice)
}
